<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<c:set var="ctx" value="${pageContext.request.contextPath}"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>供应商资料</title>
	<jsp:include page="../../import.jsp" flush="true"/>
	<script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div class="fieldset1 tabel_col tabel_col_s clearFix">
		<div class="sqPanel">
			<div class="sqPanel_head inL">
				<span>经销商资料</span>
				<span class="btns"><span class="sq-button sq-button-round" onclick="downloadSplFileByUrl();">打包下载</span></span>
			</div>
			<div class="sqPanel_body">
				<div id="splFileInfoCfgGrid" class="sq-grid"></div>
			</div>
		</div>
		<%-- <c:if test="${not empty splAttrCd and splAttrCd == '1' and not empty isDetail and isDetail == '1'}">
             <div class="sqPanel">
                 <div class="sqPanel_head inL">
                     <span>配偶资料信息</span>
                     <span class="btns"><span class="sq-button sq-button-round" onclick="downloadSplFileByUrl();">打包下载</span></span>
                 </div>
                 <div class="sqPanel_body">
                     <div id="splNpPcInfoCfgGrid" class="sq-grid"></div>
                 </div>
             </div>
         </c:if>--%>
	</div>
	<!-- 资料上传DIV -->
	<div id="prj_file_div" style="display:none">
		<form id="prj_file_formSet">
			<div class="fieldset1 tabel_col noBorder clearFix">
				<div class="fieldBox col_100">
					<jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp" flush="true" >
						<jsp:param name="fileNum" value="1"/>
						<jsp:param name="filePath" value="prjFileInfo"/>
					</jsp:include>
				</div>
			</div>
			<input type="text" style="display: none;" id="cfgCd" name="cfgCd" value="${cfgCd}">
			<input type="text" style="display: none;" id="cfgDtlCd" name="cfgDtlCd">
			<input type="text" style="display: none;" id="orgCd" name="orgCd" value="${cfgOrgCd}">
			<input name="splId" id="splId" type="hidden" value="${splId}"/>
		</form>
	</div>

	<div class="pageInTab">
		<form id="formSet1">
			<div class="fieldset1 tabel_col clearFix">
				<%--<div class="sqPanel">
                    <c:if test="${not empty fileDtlList }">
                        <c:forEach items="${fileDtlList}" var="fileRec" varStatus="status">
                            <div class="sqPanel_head inL">
                                <span>${fileRec.cfgNm}</span>
                            </div>
                            <table class="table_full tbl_1">
                                <tbody>
                                <tr>
                                    <c:forEach items="${fileRec.data }" var="cfgDtlList" varStatus="varStatus">
                                    <c:if test="${varStatus.index % 4==0}">
                                </tr>
                                <tr>
                                    </c:if>
                                    <td>
                                        <h5>${cfgDtlList.cfgDtlCdNm}</h5>
                                        <div class="imgBox">
                                            <c:if test="${ empty cfgDtlList.fileRecVos}">
                                                <img src="${defImg}" onclick="showImg(event);" fileId="">
                                            </c:if>
                                            <c:if test="${ not empty cfgDtlList.fileRecVos}">
                                                <c:if test="${ empty cfgDtlList.fileRecVos[0].filePath}">
                                                    <img src="${defImg}" onclick="showImg(event);" fileId="">
                                                </c:if>
                                                <c:if test="${ not empty cfgDtlList.fileRecVos[0].filePath}">
                                                    <img id="imgPath" src="${cfgDtlList.fileRecVos[0].filePath}" onclick="showImg(event);"
                                                         href="${cfgDtlList.fileRecVos[0].filePath}" fileId="">
                                                </c:if>
                                            </c:if>
                                        </div>
                                        <div class="btns">
                                            <c:if test="${isDetail !=1 }">
                                                <c:if test="${ empty cfgDtlList.fileRecVos or empty cfgDtlList.fileRecVos[0].filePath}">
                                                <span class="sq-button sq-button-round co_normal" sysCd="${fileRec.sysCd}"
                                                      orgCd="${fileRec.orgCd}" cfgCd="${fileRec.cfgCd}"
                                                      cfgDtlCd="${cfgDtlList.cfgDtlCd}"
                                                      onclick="uploadFile(this,'${fileRec.sysCd}','${fileRec.orgCd}','${fileRec.cfgCd}','${cfgDtlList.cfgDtlCd}')">上传</span>

                                                </c:if>
                                                <c:if test="${ not empty cfgDtlList.fileRecVos and not empty cfgDtlList.fileRecVos[0].filePath}">
                                                    <span class="sq-button sq-button-round co_normal">
                                                    <a target="_blank"
                                                     href="<%=path%>/system/sysulfilesrec/downLoad.do?fileName=${cfgDtlList.fileRecVos[0].fileNm}&filePath=${cfgDtlList.fileRecVos[0].filePath}">下载</a>
                                                    </span>
                                                    <span class="sq-button sq-button-round co_normal"
                                                          onclick="removeFileRec(this,'${cfgDtlList.fileRecVos[0].id}')">删除</span>
                                                </c:if>
                                            </c:if>
                                        </div>
                                    </td>
                                    </c:forEach>
                                </tr>
                                </tbody>
                            </table>
                        </c:forEach>
                    </c:if>
                </div>--%>
				<c:if test="${not empty splAttrCd and splAttrCd == '2' and not empty isMatchFileRec and isMatchFileRec == '0'}">
					<div class="caption">
						<span class="title">全部资料信息</span>
					</div>
					<c:if test="${isDetail==1 }">
						<div class="fieldBox col_100">
							<div id="fileList">
								<jsp:include page="../../system/sysUlFilesRec/sysUlFileRecListDetail.jsp" flush="true">
									<jsp:param name="pkId" value="${splId }"/>
									<jsp:param name="tabNm" value="${tabNm}"/>
									<jsp:param name="isShowAudStsCd" value="1"/>
								</jsp:include>
							</div>
						</div>
					</c:if>
					<c:if test="${isDetail!=1 }">
						<div class="fieldBox col_100">
							<div id="fileList">
								<jsp:include page="../../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true">
									<jsp:param name="pkId" value="${splId }"/>
									<jsp:param name="tabNm" value="${tabNm}"/>
									<jsp:param name="isShowAudStsCd" value="1"/>
								</jsp:include>
							</div>
						</div>
					</c:if>
				</c:if>
			</div>
		</form>
	</div>
</div>

<script type="text/javascript">
    var _splId = '${splId}';
    var _isDetail = '${isDetail}';
    var _splAttrCd = '${splAttrCd }'; //经销商类型 自然人法人
    var _qualTypCd = '${qualTypCd }'; //经销商资质
    var _cfgSysCd = '${cfgSysCd}'; //附件系统CODE
    var _cfgOrgCd = '${cfgOrgCd}'; //附件组织架构
    var _tabNm = '${tabNm}'; //附件对应表
    var _cfgCd = '${cfgCd}'; //附件CODE
    var _modulePath = '${modulePath}';
    var _costomerPath = '${costomerPath}';
    var _rootPath = '${rootPath}';
    var _uploadSysCd = '${uploadSysCd}';
    var _isApply = '${isApply}';
    var _isCheckVerify = '${isCheckVerify}';

    var splNpPcInfoCfgGrid = null ;//自然人经销商配偶资料信息
    var splFileInfoCfgGrid = null ;//经销商资料配置明细
    var isMatchFileRec = '${isMatchFileRec}';

    $(function () {
        $('#formSet1').ligerForm({
            validate: true
        });

        //经销商资料配置明细Grid
        splFileInfoCfgGrid = $("#splFileInfoCfgGrid").ligerGrid({
            url: '<%=path%>/product/splInfo/initSplFileInfoList.do?splId='+_splId+'&cfgCd='+_cfgCd +'&tabNm='+_tabNm +"&cfgSysCd="+_cfgSysCd+'&cfgOrgCd='+_cfgOrgCd,
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm',align: 'left', minWidth: 100, enabledSort: false},
                {display: '上传文件名称', name: 'fileNm',align: 'left', minWidth: 100, enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm',align: 'left', minWidth: 100, enabledSort: false,render:renderDate},
                {display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},
                {display: '操作', name: '', minWidth: 100,align: 'left',  enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        if(_isApply){
                            if(_isDetail && _isDetail == 1){
                                if(_isCheckVerify && _isCheckVerify == 1){
                                    h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId + ',1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                    h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId + ',2);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                                }
                            }
                        }else{
                            if(rowdata.fileId){
                                if(rowdata.audStsCd && rowdata.audStsCd != 1 && _isDetail && _isDetail != 1){
                                    h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                                }
                            }
                        }
                        return h;
                    }
                },
                {display: '上传', name: 'uploadNm', width: 80,align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        if(_isDetail !=1){
                            if(_isApply){

                            }else{
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',\''+rowdata.fileId+'\',\''+rowindex+'\')"></span>';
                            }
                        }
                        return h;
                    }
                },
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers:true,  //显示序号
            checkbox: false,
            allowUnSelectRow:true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function ()
            {
                $('#splFileInfoCfgGrid').rowspan('datNm');
                $('#splFileInfoCfgGrid').rowspan('uploadNm');
            },
        });
    });

    function onChangefile_multi(e,cfgCd,cfgDtlCd,orgCd,fileId,rowIndex) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath= _modulePath; //之前无 '/'
        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath,costomerPath:_costomerPath,rootPath:_rootPath,uploadSysCd:_uploadSysCd},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {'fileParams':JSON.stringify(msg.data),'splId':$("#splId").val(),'cfgCd':cfgCd,'cfgDtlCd':cfgDtlCd,'orgCd':orgCd,'cfgSysCd':_cfgSysCd,'rootPath':_rootPath,'tabNm':_tabNm,"fileId":fileId},
                        //url: '<%=path%>/project/prjFileInfo/uploadCstFile.do',
                        url: '<%=path%>/product/splInfo/addSplFileList.do',
                        success: function (msg) {
                            if (msg.success == 1) {
                                splFileInfoCfgGrid.reload();
                                if(StringUtils.isNotEmpty(_splAttrCd) && _splAttrCd == '2' && StringUtils.isNotEmpty(isMatchFileRec) && isMatchFileRec == '0'){
                                    refreshUlFileRecList();//刷新文件列表
                                    clearUploadResultParams();//清除上传结果参数
                                }
                            }else{
                                $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                            }
                            $.ligerDialog.hide();
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    };

    //修改资料的验证状态
    function modifyAudStsCd(event,_fileId,_audStsCd){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId':_fileId,'audStsCd':_audStsCd},
            url: '<%=path%>/product/splInfo/modifyFileAudStsCd.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    //$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    event.stopPropagation();
                    var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                    liger.get(gridID).reload();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //删除文件
    function delFile(event,_fileId){
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if(!flag){
                return;
            }else{
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId':_fileId},
                    url: '<%=path%>/product/splInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            event.stopPropagation();
                            if(StringUtils.isNotEmpty(_splAttrCd) && _splAttrCd == '2' && StringUtils.isNotEmpty(isMatchFileRec) && isMatchFileRec == '0'){
                                refreshUlFileRecList();//刷新文件列表
                                clearUploadResultParams();//清除上传结果参数
                            }
                            var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                            liger.get(gridID).reload();
                        }else{
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    function downloadSplFileByUrl() {
        var data = splFileInfoCfgGrid.getData();
        //var files = [];
        var ids = [];
        for (var i = 0; i < data.length; i++) {
            var map = {};
            if(StringUtils.isNotEmpty(data[i].fileId)){
                ids.push(data[i].fileId);
            }
        }
        var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do?';
        var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }

    /*var splId = '${splId}';

    function save() {
        if (StringUtils.isEmpty(splId)) {
            $.ligerDialog.SQalert({content: "供应商ID不存在.", SQ_type: "warning"});
        }
        var form = liger.get("formSet1");
        var data = form.getData();
        var fileParams = getUploadResultParams(); //获取附件上传的信息
        data["fileParams"] = JSON.stringify(fileParams);
        data["splId"] = splId;

        var url = '<%=path%>/product/splInfo/addSplFileList.do';
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    refreshUlFileRecList();//刷新文件列表
                    clearUploadResultParams();//清除上传结果参数
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }*/


    //图片上传
    /*    function uploadFile(imgObj,sysCd,orgCd,cfgCd,cfgDtlCd){
            if(StringUtils.isEmpty( $("#splId").val())){
                $.ligerDialog.SQalert({content: LogUtils.LOG_SPL_BSC_INFO_ADD , SQ_type: "warning" });
                return false; //验证不通过，不执行以下代码
            }
            var _id = $("#splId").val();//供应商id
            var obj = $(imgObj).parent().parent().find("img")
            var  url = '<%=path%>/product/splInfo/addInvestImgPage.do?sysCd='+sysCd+'&orgCd='+orgCd+'&cfgCd='+cfgCd+'&cfgDtlCd='+cfgDtlCd+'&id='+_id;
        $.ligerDialog.open({
            height:300,
            width: 600,
            title : '上传图片',
            url: url,
            showMax: false,
            showToggle: true,
            showMin: false,
            isResize: true,
            slide: false,
            data: {
                imgObj: obj
            },
        });
    }*/

    //图片展示
    function showImg(e){
        e.preventDefault();
        var href = $(e.target).attr('src');
        if(!href){
            return;
        }
        if(SQ.regs.img.test(href)){
            var imgSrc = $(e.target).attr('src'),
                imgTit = $(e.target).attr('title');
            window.__ImgSrc = imgSrc;
            window.__ImgTit = imgTit;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }
    }

    //删除文件
    function removeFileRec(event,_fileId){
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if(!flag){
                return;
            }else{
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId':_fileId},
                    url: '<%=path%>/product/splInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            //parent.$('li[tabid="mateTab"] a').text('项目资料('+msg.data+')');
                            refreshUlFileRecList();//刷新文件列表
                            clearUploadResultParams();//清除上传结果参数

                            var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                            liger.get(gridID).reload();
                            //var gridID = $(event.target).parents('.sq-grid').attr('ligergrid1');
                            //liger.get(gridID).reload();
                        }else{
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            //SQ.imgPreview(_url);
            //SQ.imgPreview(_url, true);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }
</script>


</body>
</html>